# -*- coding:utf-8 -*-

import os
import shutil
import unittest
from time import sleep

from selenium import webdriver
from selenium.webdriver.support.ui import Select
from AutoTestBDC.WorkFlow.User import User
from AutoTestBDC.WorkFlow.WorkFlow import WorkFlow
from AutoTestBDC.extScript.Excel import RdExcel
from AutoTestBDC.extScript.ParseBDCType import BDCType
from AutoTestBDC.extScript.ReadTextFile import ReadTestFile
from AutoTestBDC.extScript.UploadPic import UploadPic


class QYFR(unittest.TestCase):
    def setUp(self):
        # self.driver = webdriver.Firefox()
        iedriver = os.getcwd() + "\\IEDriverServer.exe"
        os.environ["webdriver.ie.driver"] = iedriver
        self.driver = webdriver.Ie(executable_path=iedriver)

        self.driver.maximize_window()
        self.driver.implicitly_wait(10)
        self.base_url = "http://192.168.200.248:8080"
        self.verificationErrors = []
        self.accept_next_alert = True

        self.casedate = RdExcel()
        self.caselist = self.casedate.getUserCaseByExcel("法人机构")

        self.driver.get(self.base_url + "/RealestateTrade")
        User().Login(self.driver)
        self.dbt = BDCType()

    def test_frtester(self):
        driver = self.driver
        list = self.caselist

        for dist in list:
            try:
                driver.find_element_by_xpath("/html/body/header/div[2]/ul[1]/li[1]/a").click()
            except Exception as e:
                sleep(2)
                driver.find_element_by_xpath("/html/body/header/div[2]/ul[1]/li[1]/a").click()

            if dist["法人机构类型"] == "企业法人":
                self.qyfr(driver, dist)
            if dist["法人机构类型"] == "事业法人":
                self.syfr(driver, dist)
            if dist["法人机构类型"] == "机关法人":
                self.jgfr(driver, dist)
            if dist["法人机构类型"] == "社会团体法人":
                self.stfr(driver, dist)

            User().Logout(self.driver)
            # driver.find_element_by_xpath("/html/body/header/div[2]/div/ul/li[3]/a").click()
            # 走各种流程
            WorkFlow(self.driver, ReadTestFile().get_danganno()[3:], "法人机构")
            User().Login(self.driver)

    # 企业法人
    def qyfr(self, driver, dist):

        # 选择委托类型
        try:
            driver.find_element_by_link_text(dist["委托类型"]).click()
        except:
            self.movedownPage(driver, elementXPATH="/html/body/content/div/div[3]/div[2]/div[2]/ul/li[3]/a/h2")
            driver.find_element_by_link_text(dist["委托类型"]).click()

        # 选择委托类型
        Select(driver.find_element_by_id("entrustedPersons")).select_by_visible_text(dist["权利人类型"])
        Select(driver.find_element_by_id("org-type")).select_by_visible_text(dist["法人机构类型"])

        # 是否代办
        driver.find_element_by_name("isAgency").click()

        driver.find_element_by_id("entrustedOrg").clear()
        driver.find_element_by_id("entrustedOrg").send_keys(dist["委托机构名称"])

        # 负责人姓名
        strname = dist["法定代表人"] + "_" + str(ReadTestFile().readfile())

        driver.find_element_by_id("legalPerson").clear()
        driver.find_element_by_id("legalPerson").send_keys(strname)
        driver.find_element_by_id("legalIdCard").clear()
        driver.find_element_by_id("legalIdCard").send_keys(dist["法定代表人身份证号"])

        driver.find_element_by_id("copy1").click()
        # 这里要上传一张身份证照片-----------------------------------------
        # 选择机构负责人照片上传
        UploadPic(driver, "/html/body/content/div/form/div/div[6]/div[2]/div[3]/div[1]/div[1]/div[2]/div",
                  dist["身份证电子件"]).upfile("/html/body/content/div/form/div/div[6]/div[2]/div[3]/div[1]/div[1]/div[2]/a")

        driver.find_element_by_id("contactMobile").clear()
        driver.find_element_by_id("contactMobile").send_keys(dist["联系手机"])
        driver.find_element_by_id("contactPhone").clear()
        driver.find_element_by_id("contactPhone").send_keys(dist["联系电话"])
        driver.find_element_by_name("obligeeInfo.obligeeEmail").clear()
        driver.find_element_by_name("obligeeInfo.obligeeEmail").send_keys(dist["电子邮件"])
        driver.find_element_by_id("postCode").clear()
        driver.find_element_by_id("postCode").send_keys(dist["邮编"])
        Select(driver.find_element_by_xpath(
            "/html/body/content/div/form/div/div[6]/div[9]/div[3]/span[1]/select")).select_by_visible_text(
            dist["联系地址-省"])
        Select(driver.find_element_by_xpath(
            "/html/body/content/div/form/div/div[6]/div[9]/div[3]/span[2]/select")).select_by_visible_text(
            dist["联系地址-市"])
        Select(driver.find_element_by_xpath(
            "/html/body/content/div/form/div/div[6]/div[9]/div[3]/span[3]/select")).select_by_visible_text(
            dist["联系地址-区"])
        driver.find_element_by_id("street1").clear()
        driver.find_element_by_xpath("/html/body/content/div/form/div/div[6]/div[10]/div[3]/input").send_keys(
            dist["联系地址-街"])
        driver.find_element_by_id("streetNo1").clear()
        driver.find_element_by_xpath("/html/body/content/div/form/div/div[6]/div[10]/div[5]/input").send_keys(
            dist["联系地址-号"])

        if dist["法人机构类型"] == "企业法人":
            # 对营业执照号码可见
            self.movedownPage(driver, elementXPATH="/html/body/content/div/form/div/div[7]/div[1]/div[1]")

            driver.find_element_by_id("businessLice").clear()
            driver.find_element_by_id("businessLice").send_keys(dist["营业执照号码"])

            driver.find_element_by_id("copy2").click()
            # 这里要上传一张身份证照片-----------------------------------------
            # 上传营业执照电子件
            UploadPic(driver, "/html/body/content/div/form/div/div[7]/div[3]/div[3]/div[1]/div[1]/div[2]/div",
                      dist["营业执照电子件"]).upfile(
                "/html/body/content/div/form/div/div[7]/div[3]/div[3]/div[1]/div[1]/div[2]/a")

        driver.find_element_by_id("orgCode").clear()
        driver.find_element_by_id("orgCode").send_keys(dist["组织机构代码证号124"])

        driver.find_element_by_id("copy3").click()
        UploadPic(driver, "/html/body/content/div/form/div/div[7]/div[7]/div[3]/div[1]/div[1]/div[2]/div",
                  dist["组织机构代码证电子件124"]).upfile(
            "/html/body/content/div/form/div/div[7]/div[7]/div[3]/div[1]/div[1]/div[2]/a")

        driver.find_element_by_id("taxCerti").clear()
        driver.find_element_by_id("taxCerti").send_keys(dist["税务登记证号码"])

        driver.find_element_by_id("copy4").click()
        # 这里要上传一张身份证照片-----------------------------------------
        # 税务登记证电子件
        UploadPic(driver, "/html/body/content/div/form/div/div[7]/div[11]/div[3]/div[1]/div[1]/div[2]/div",
                  dist["税务登记证电子件"]).upfile(
            "/html/body/content/div/form/div/div[7]/div[11]/div[3]/div[1]/div[1]/div[2]/a")

        # 对受托人姓名S可见
        # self.movedownPage(driver, elementID='copy12')


        driver.find_element_by_id("depositaryName").clear()
        driver.find_element_by_id("depositaryName").send_keys(dist["受托人姓名S"])
        driver.find_element_by_id("depositaryIdCard").clear()
        driver.find_element_by_id("depositaryIdCard").send_keys(dist["受托人身份证号S"])

        # self.movedownPage(driver, elementXPATH='//*[@id="next-step1"]')
        self.movedownPage(driver, elementID="copy4")

        sleep(1)
        driver.find_element_by_id("copy12").click()

        UploadPic(driver, "/html/body/content/div/form/div/div[12]/div[4]/div[3]/div[1]/div[1]/div[2]/div",
                  dist["身份证电子件S"]).upfile(
            "/html/body/content/div/form/div/div[12]/div[4]/div[3]/div[1]/div[1]/div[2]/a")

        self.movedownPage(driver, elementXPATH='//*[@id="next-step1"]')

        driver.find_element_by_id("contactMobile1").clear()
        driver.find_element_by_id("contactMobile1").send_keys(dist["联系手机S"])
        driver.find_element_by_id("contactPhone1").clear()
        driver.find_element_by_id("contactPhone1").send_keys(dist["联系电话S"])
        driver.find_element_by_name("baileeInfo.baileeEmail").clear()
        driver.find_element_by_name("baileeInfo.baileeEmail").send_keys(dist["电子邮件S"])
        driver.find_element_by_name("baileeInfo.postCode").clear()
        driver.find_element_by_name("baileeInfo.postCode").send_keys(dist["邮编S"])
        Select(driver.find_element_by_xpath(
            "/html/body/content/div/form/div/div[12]/div[11]/div[3]/span[1]/select")).select_by_visible_text(
            dist["联系地址-省S"])
        Select(driver.find_element_by_xpath(
            "/html/body/content/div/form/div/div[12]/div[11]/div[3]/span[2]/select")).select_by_visible_text(
            dist["联系地址-市S"])
        Select(driver.find_element_by_xpath(
            "/html/body/content/div/form/div/div[12]/div[11]/div[3]/span[3]/select")).select_by_visible_text(
            dist["联系地址-区S"])
        driver.find_element_by_id("baileeStreetName").clear()
        driver.find_element_by_xpath("/html/body/content/div/form/div/div[12]/div[12]/div[3]/input").send_keys(
            dist["联系地址-街S"])
        driver.find_element_by_id("baileeStreetNo").clear()
        driver.find_element_by_xpath("/html/body/content/div/form/div/div[12]/div[12]/div[5]/input").send_keys(
            dist["联系地址-号S"])

        # self.movedownPage(driver, elementXPATH='//*[@id="next-step1"]')

        driver.find_element_by_id("textarea1").clear()
        driver.find_element_by_id("textarea1").send_keys(dist["备注"])

        driver.find_element_by_id("next-step1").click()

        # 不动产信息
        self.dbt.changeGotoInfoMessage(driver, dist["不动产类型"], dist["不动产登记类型用例"])

        # 不动产类型信息
        self.dbt.changeGotoWTType(driver, dist["委托类型"], dist["委托类型用例"])

    # 事业法人
    def syfr(self, driver, dist):
        # 选择委托类型
        try:
            driver.find_element_by_link_text(dist["委托类型"]).click()
        except:
            self.movedownPage(driver, elementXPATH="/html/body/content/div/div[3]/div[2]/div[2]/ul/li[3]/a/h2")
            driver.find_element_by_link_text(dist["委托类型"]).click()

        # 选择委托类型
        Select(driver.find_element_by_id("entrustedPersons")).select_by_visible_text(dist["权利人类型"])
        Select(driver.find_element_by_id("org-type")).select_by_visible_text(dist["法人机构类型"])

        # 是否代办
        driver.find_element_by_name("isAgency").click()

        driver.find_element_by_id("entrustedOrg").clear()
        driver.find_element_by_id("entrustedOrg").send_keys(dist["委托机构名称"])

        # 负责人姓名
        strname = dist["法定代表人"] + "_" + str(ReadTestFile().readfile())

        driver.find_element_by_id("legalPerson").clear()
        driver.find_element_by_id("legalPerson").send_keys(strname)
        driver.find_element_by_id("legalIdCard").clear()
        driver.find_element_by_id("legalIdCard").send_keys(dist["法定代表人身份证号"])

        driver.find_element_by_id("copy1").click()
        # 这里要上传一张身份证照片-----------------------------------------
        # 选择机构负责人照片上传
        UploadPic(driver, "/html/body/content/div/form/div/div[6]/div[2]/div[3]/div[1]/div[1]/div[2]/div",
                  dist["身份证电子件"]).upfile(
            "/html/body/content/div/form/div/div[6]/div[2]/div[3]/div[1]/div[1]/div[2]/a")

        driver.find_element_by_id("contactMobile").clear()
        driver.find_element_by_id("contactMobile").send_keys(dist["联系手机"])
        driver.find_element_by_id("contactPhone").clear()
        driver.find_element_by_id("contactPhone").send_keys(dist["联系电话"])
        driver.find_element_by_name("obligeeInfo.obligeeEmail").clear()
        driver.find_element_by_name("obligeeInfo.obligeeEmail").send_keys(dist["电子邮件"])
        driver.find_element_by_id("postCode").clear()
        driver.find_element_by_id("postCode").send_keys(dist["邮编"])
        Select(driver.find_element_by_xpath(
            "/html/body/content/div/form/div/div[6]/div[9]/div[3]/span[1]/select")).select_by_visible_text(
            dist["联系地址-省"])
        Select(driver.find_element_by_xpath(
            "/html/body/content/div/form/div/div[6]/div[9]/div[3]/span[2]/select")).select_by_visible_text(
            dist["联系地址-市"])
        Select(driver.find_element_by_xpath(
            "/html/body/content/div/form/div/div[6]/div[9]/div[3]/span[3]/select")).select_by_visible_text(
            dist["联系地址-区"])
        driver.find_element_by_id("street1").clear()
        driver.find_element_by_xpath("/html/body/content/div/form/div/div[6]/div[10]/div[3]/input").send_keys(
            dist["联系地址-街"])
        driver.find_element_by_id("streetNo1").clear()
        driver.find_element_by_xpath("/html/body/content/div/form/div/div[6]/div[10]/div[5]/input").send_keys(
            dist["联系地址-号"])

        # 事业法人字段
        if dist["法人机构类型"] == "事业法人":
            # 对营业执照号码可见
            self.movedownPage(driver, elementID="careerLegalIdCard")

            driver.find_element_by_id("careerLegalIdCard").clear()
            driver.find_element_by_id("careerLegalIdCard").send_keys(u"事业单位法人证号码")

            # self.movedownPage(driver, elementID="copy5")
            driver.find_element_by_id("copy5").click()
            # driver.find_element_by_xpath("/html/body/content/div/form/div/div[8]/div[2]/div[3]/input").click()

            # 上传事业单位法人证电子件电子件
            UploadPic(driver, "/html/body/content/div/form/div/div[8]/div[3]/div[3]/div[1]/div[1]/div[2]/div",
                      dist["事业单位法人证电子件"]).upfile(
                "/html/body/content/div/form/div/div[8]/div[3]/div[3]/div[1]/div[1]/div[2]/a")

        # 这里要上传一张身份证照片-----------------------------------------
        # 上传组织机构代码证电子件
        driver.find_element_by_id("orgCode1").clear()
        driver.find_element_by_id("orgCode1").send_keys(dist["组织机构代码证号124"])

        driver.find_element_by_id("copy6").click()

        UploadPic(driver, "/html/body/content/div/form/div/div[8]/div[7]/div[3]/div[1]/div[1]/div[2]/div"
                  , dist["组织机构代码证电子件124"]).upfile(
            "/html/body/content/div/form/div/div[8]/div[7]/div[3]/div[1]/div[1]/div[2]/a")

        # 对受托人姓名S可见
        driver.find_element_by_id("depositaryName").clear()
        driver.find_element_by_id("depositaryName").send_keys(dist["受托人姓名S"])
        driver.find_element_by_id("depositaryIdCard").clear()
        driver.find_element_by_id("depositaryIdCard").send_keys(dist["受托人身份证号S"])

        sleep(1)
        driver.find_element_by_id("copy12").click()

        sleep(2)
        UploadPic(driver, "/html/body/content/div/form/div/div[12]/div[4]/div[3]/div[1]/div[1]/div[2]/div"
                  , dist["身份证电子件S"]).upfile(
            "/html/body/content/div/form/div/div[12]/div[4]/div[3]/div[1]/div[1]/div[2]/a")

        self.movedownPage(driver, elementXPATH='//*[@id="next-step1"]')

        driver.find_element_by_id("contactMobile1").clear()
        driver.find_element_by_id("contactMobile1").send_keys(dist["联系手机S"])
        driver.find_element_by_id("contactPhone1").clear()
        driver.find_element_by_id("contactPhone1").send_keys(dist["联系电话S"])
        driver.find_element_by_name("baileeInfo.baileeEmail").clear()
        driver.find_element_by_name("baileeInfo.baileeEmail").send_keys(dist["电子邮件S"])
        driver.find_element_by_name("baileeInfo.postCode").clear()
        driver.find_element_by_name("baileeInfo.postCode").send_keys(dist["邮编S"])
        Select(driver.find_element_by_xpath(
            "/html/body/content/div/form/div/div[12]/div[11]/div[3]/span[1]/select")).select_by_visible_text(
            dist["联系地址-省S"])
        Select(driver.find_element_by_xpath(
            "/html/body/content/div/form/div/div[12]/div[11]/div[3]/span[2]/select")).select_by_visible_text(
            dist["联系地址-市S"])
        Select(driver.find_element_by_xpath(
            "/html/body/content/div/form/div/div[12]/div[11]/div[3]/span[3]/select")).select_by_visible_text(
            dist["联系地址-区S"])
        driver.find_element_by_id("baileeStreetName").clear()
        driver.find_element_by_xpath("/html/body/content/div/form/div/div[12]/div[12]/div[3]/input").send_keys(
            dist["联系地址-街S"])
        driver.find_element_by_id("baileeStreetNo").clear()
        driver.find_element_by_xpath("/html/body/content/div/form/div/div[12]/div[12]/div[5]/input").send_keys(
            dist["联系地址-号S"])

        driver.find_element_by_id("textarea1").clear()
        driver.find_element_by_id("textarea1").send_keys(dist["备注"])

        driver.find_element_by_id("next-step1").click()

        # 不动产信息
        self.dbt.changeGotoInfoMessage(driver, dist["不动产类型"], dist["不动产登记类型用例"])

        # 不动产类型信息
        self.dbt.changeGotoWTType(driver, dist["委托类型"], dist["委托类型用例"])

    # 机关法人
    def jgfr(self, driver, dist):

        # 选择委托类型
        try:
            driver.find_element_by_link_text(dist["委托类型"]).click()
        except:
            self.movedownPage(driver, elementXPATH="/html/body/content/div/div[3]/div[2]/div[2]/ul/li[3]/a/h2")
            driver.find_element_by_link_text(dist["委托类型"]).click()

        # 选择委托类型
        Select(driver.find_element_by_id("entrustedPersons")).select_by_visible_text(dist["权利人类型"])
        Select(driver.find_element_by_id("org-type")).select_by_visible_text(dist["法人机构类型"])

        # 是否代办
        driver.find_element_by_name("isAgency").click()

        driver.find_element_by_id("entrustedOrg").clear()
        driver.find_element_by_id("entrustedOrg").send_keys(dist["委托机构名称"])

        # 负责人姓名
        strname = dist["法定代表人"] + "_" + str(ReadTestFile().readfile())

        driver.find_element_by_id("legalPerson").clear()
        driver.find_element_by_id("legalPerson").send_keys(strname)
        driver.find_element_by_id("legalIdCard").clear()
        driver.find_element_by_id("legalIdCard").send_keys(dist["法定代表人身份证号"])

        driver.find_element_by_id("copy1").click()
        # 这里要上传一张身份证照片-----------------------------------------
        # 选择机构负责人照片上传
        UploadPic(driver, "/html/body/content/div/form/div/div[6]/div[2]/div[3]/div[1]/div[1]/div[2]/div",
                  dist["身份证电子件"]).upfile(
            "/html/body/content/div/form/div/div[6]/div[2]/div[3]/div[1]/div[1]/div[2]/a")

        driver.find_element_by_id("contactMobile").clear()
        driver.find_element_by_id("contactMobile").send_keys(dist["联系手机"])
        driver.find_element_by_id("contactPhone").clear()
        driver.find_element_by_id("contactPhone").send_keys(dist["联系电话"])
        driver.find_element_by_name("obligeeInfo.obligeeEmail").clear()
        driver.find_element_by_name("obligeeInfo.obligeeEmail").send_keys(dist["电子邮件"])
        driver.find_element_by_id("postCode").clear()
        driver.find_element_by_id("postCode").send_keys(dist["邮编"])
        Select(driver.find_element_by_xpath(
            "/html/body/content/div/form/div/div[6]/div[9]/div[3]/span[1]/select")).select_by_visible_text(
            dist["联系地址-省"])
        Select(driver.find_element_by_xpath(
            "/html/body/content/div/form/div/div[6]/div[9]/div[3]/span[2]/select")).select_by_visible_text(
            dist["联系地址-市"])
        Select(driver.find_element_by_xpath(
            "/html/body/content/div/form/div/div[6]/div[9]/div[3]/span[3]/select")).select_by_visible_text(
            dist["联系地址-区"])
        driver.find_element_by_id("street1").clear()
        driver.find_element_by_xpath("/html/body/content/div/form/div/div[6]/div[10]/div[3]/input").send_keys(
            dist["联系地址-街"])
        driver.find_element_by_id("streetNo1").clear()
        driver.find_element_by_xpath("/html/body/content/div/form/div/div[6]/div[10]/div[5]/input").send_keys(
            dist["联系地址-号"])

        self.movedownPage(driver, elementID="street1")

        driver.find_element_by_id("copy7").click()

        # 选择政府同意办理的批文电子件上传
        UploadPic(driver, "/html/body/content/div/form/div/div[9]/div[2]/div[3]/div[1]/div[1]/div[2]/div",
                  dist["政府同意办理的批文电子件"]).upfile(
            "/html/body/content/div/form/div/div[9]/div[2]/div[3]/div[1]/div[1]/div[2]/a")

        driver.find_element_by_id("copy8").click()

        # 选择单位介绍信电子件上传
        UploadPic(driver, "/html/body/content/div/form/div/div[9]/div[5]/div[3]/div[1]/div[1]/div[2]/div",
                  dist["单位介绍信电子件"]).upfile(
            "/html/body/content/div/form/div/div[9]/div[5]/div[3]/div[1]/div[1]/div[2]/a")

        driver.find_element_by_id("depositaryName").clear()
        driver.find_element_by_id("depositaryName").send_keys(dist["受托人姓名S"])
        driver.find_element_by_id("depositaryIdCard").clear()
        driver.find_element_by_id("depositaryIdCard").send_keys(dist["受托人身份证号S"])

        # self.movedownPage(driver,elementID="copy12")
        sleep(1)
        driver.find_element_by_id("copy12").click()
        # driver.find_element_by_xpath("/html/body/content/div/form/div/div[12]/div[3]/div[3]/input").click()

        sleep(2)

        UploadPic(driver, "/html/body/content/div/form/div/div[12]/div[4]/div[3]/div[1]/div[1]/div[2]/div",
                  dist["身份证电子件S"]).upfile(
            "/html/body/content/div/form/div/div[12]/div[4]/div[3]/div[1]/div[1]/div[2]/a")

        self.movedownPage(driver, elementXPATH='//*[@id="next-step1"]')

        driver.find_element_by_id("contactMobile1").clear()
        driver.find_element_by_id("contactMobile1").send_keys(dist["联系手机S"])
        driver.find_element_by_id("contactPhone1").clear()
        driver.find_element_by_id("contactPhone1").send_keys(dist["联系电话S"])
        driver.find_element_by_name("baileeInfo.baileeEmail").clear()
        driver.find_element_by_name("baileeInfo.baileeEmail").send_keys(dist["电子邮件S"])
        driver.find_element_by_name("baileeInfo.postCode").clear()
        driver.find_element_by_name("baileeInfo.postCode").send_keys(dist["邮编S"])
        Select(driver.find_element_by_xpath(
            "/html/body/content/div/form/div/div[12]/div[11]/div[3]/span[1]/select")).select_by_visible_text(
            dist["联系地址-省S"])
        Select(driver.find_element_by_xpath(
            "/html/body/content/div/form/div/div[12]/div[11]/div[3]/span[2]/select")).select_by_visible_text(
            dist["联系地址-市S"])
        Select(driver.find_element_by_xpath(
            "/html/body/content/div/form/div/div[12]/div[11]/div[3]/span[3]/select")).select_by_visible_text(
            dist["联系地址-区S"])
        driver.find_element_by_id("baileeStreetName").clear()
        driver.find_element_by_xpath("/html/body/content/div/form/div/div[12]/div[12]/div[3]/input").send_keys(
            dist["联系地址-街S"])
        driver.find_element_by_id("baileeStreetNo").clear()
        driver.find_element_by_xpath("/html/body/content/div/form/div/div[12]/div[12]/div[5]/input").send_keys(
            dist["联系地址-号S"])

        # self.movedownPage(driver, elementXPATH='//*[@id="next-step1"]')

        driver.find_element_by_id("textarea1").clear()
        driver.find_element_by_id("textarea1").send_keys(dist["备注"])

        driver.find_element_by_id("next-step1").click()

        # 不动产信息
        self.dbt.changeGotoInfoMessage(driver, dist["不动产类型"], dist["不动产登记类型用例"])

        # 不动产类型信息
        self.dbt.changeGotoWTType(driver, dist["委托类型"], dist["委托类型用例"])

    # 社会团体法人
    def stfr(self, driver, dist):
        # 选择委托类型
        try:
            driver.find_element_by_link_text(dist["委托类型"]).click()
        except:
            self.movedownPage(driver, elementXPATH="/html/body/content/div/div[3]/div[2]/div[2]/ul/li[3]/a/h2")
            driver.find_element_by_link_text(dist["委托类型"]).click()

        # 选择委托类型
        Select(driver.find_element_by_id("entrustedPersons")).select_by_visible_text(dist["权利人类型"])
        Select(driver.find_element_by_id("org-type")).select_by_visible_text(dist["法人机构类型"])

        # 是否代办
        driver.find_element_by_name("isAgency").click()

        driver.find_element_by_id("entrustedOrg").clear()
        driver.find_element_by_id("entrustedOrg").send_keys(dist["委托机构名称"])

        # 负责人姓名
        strname = dist["法定代表人"] + "_" + str(ReadTestFile().readfile())

        driver.find_element_by_id("legalPerson").clear()
        driver.find_element_by_id("legalPerson").send_keys(strname)
        driver.find_element_by_id("legalIdCard").clear()
        driver.find_element_by_id("legalIdCard").send_keys(dist["法定代表人身份证号"])

        driver.find_element_by_id("copy1").click()
        # 这里要上传一张身份证照片-----------------------------------------
        # 选择机构负责人照片上传
        UploadPic(driver, "/html/body/content/div/form/div/div[6]/div[2]/div[3]/div[1]/div[1]/div[2]/div",
                  dist["身份证电子件"]).upfile(
            "/html/body/content/div/form/div/div[6]/div[2]/div[3]/div[1]/div[1]/div[2]/a")

        driver.find_element_by_id("contactMobile").clear()
        driver.find_element_by_id("contactMobile").send_keys(dist["联系手机"])
        driver.find_element_by_id("contactPhone").clear()
        driver.find_element_by_id("contactPhone").send_keys(dist["联系电话"])
        driver.find_element_by_name("obligeeInfo.obligeeEmail").clear()
        driver.find_element_by_name("obligeeInfo.obligeeEmail").send_keys(dist["电子邮件"])
        driver.find_element_by_id("postCode").clear()
        driver.find_element_by_id("postCode").send_keys(dist["邮编"])
        Select(driver.find_element_by_xpath(
            "/html/body/content/div/form/div/div[6]/div[9]/div[3]/span[1]/select")).select_by_visible_text(
            dist["联系地址-省"])
        Select(driver.find_element_by_xpath(
            "/html/body/content/div/form/div/div[6]/div[9]/div[3]/span[2]/select")).select_by_visible_text(
            dist["联系地址-市"])
        Select(driver.find_element_by_xpath(
            "/html/body/content/div/form/div/div[6]/div[9]/div[3]/span[3]/select")).select_by_visible_text(
            dist["联系地址-区"])
        driver.find_element_by_id("street1").clear()
        driver.find_element_by_xpath("/html/body/content/div/form/div/div[6]/div[10]/div[3]/input").send_keys(
            dist["联系地址-街"])
        driver.find_element_by_id("streetNo1").clear()
        driver.find_element_by_xpath("/html/body/content/div/form/div/div[6]/div[10]/div[5]/input").send_keys(
            dist["联系地址-号"])

        self.movedownPage(driver, elementID="socialIdCard")

        driver.find_element_by_id("socialIdCard").clear()
        driver.find_element_by_id("socialIdCard").send_keys(dist["社会团体法人证号码"])

        driver.find_element_by_id("copy9").click()
        UploadPic(driver, "/html/body/content/div/form/div/div[10]/div[3]/div[3]/div[1]/div[1]/div[2]/div",
                  dist["社会团体法人证书电子件"]).upfile(
            "/html/body/content/div/form/div/div[10]/div[3]/div[3]/div[1]/div[1]/div[2]/a")


        driver.find_element_by_id("orgCode2").clear()
        driver.find_element_by_id("orgCode2").send_keys(dist["组织机构代码证号124"])

        driver.find_element_by_id("copy10").click()
        UploadPic(driver, "/html/body/content/div/form/div/div[10]/div[7]/div[3]/div[1]/div[1]/div[2]/div",
                  dist["组织机构代码证电子件124"]).upfile(
            "/html/body/content/div/form/div/div[10]/div[7]/div[3]/div[1]/div[1]/div[2]/a")


        driver.find_element_by_id("depositaryName").clear()
        driver.find_element_by_id("depositaryName").send_keys(dist["受托人姓名S"])
        driver.find_element_by_id("depositaryIdCard").clear()
        driver.find_element_by_id("depositaryIdCard").send_keys(dist["受托人身份证号S"])

        sleep(1)
        driver.find_element_by_id("copy12").click()

        self.movedownPage(driver, elementXPATH='//*[@id="next-step1"]')

        UploadPic(driver, "/html/body/content/div/form/div/div[12]/div[4]/div[3]/div[1]/div[1]/div[2]/div",
                  dist["身份证电子件S"]).upfile(
            "/html/body/content/div/form/div/div[12]/div[4]/div[3]/div[1]/div[1]/div[2]/a")

        self.movedownPage(driver, elementXPATH='//*[@id="next-step1"]')

        driver.find_element_by_id("contactMobile1").clear()
        driver.find_element_by_id("contactMobile1").send_keys(dist["联系手机S"])
        driver.find_element_by_id("contactPhone1").clear()
        driver.find_element_by_id("contactPhone1").send_keys(dist["联系电话S"])
        driver.find_element_by_name("baileeInfo.baileeEmail").clear()
        driver.find_element_by_name("baileeInfo.baileeEmail").send_keys(dist["电子邮件S"])
        driver.find_element_by_name("baileeInfo.postCode").clear()
        driver.find_element_by_name("baileeInfo.postCode").send_keys(dist["邮编S"])
        Select(driver.find_element_by_xpath(
            "/html/body/content/div/form/div/div[12]/div[11]/div[3]/span[1]/select")).select_by_visible_text(
            dist["联系地址-省S"])
        Select(driver.find_element_by_xpath(
            "/html/body/content/div/form/div/div[12]/div[11]/div[3]/span[2]/select")).select_by_visible_text(
            dist["联系地址-市S"])
        Select(driver.find_element_by_xpath(
            "/html/body/content/div/form/div/div[12]/div[11]/div[3]/span[3]/select")).select_by_visible_text(
            dist["联系地址-区S"])
        driver.find_element_by_id("baileeStreetName").clear()
        driver.find_element_by_xpath("/html/body/content/div/form/div/div[12]/div[12]/div[3]/input").send_keys(
            dist["联系地址-街S"])
        driver.find_element_by_id("baileeStreetNo").clear()
        driver.find_element_by_xpath("/html/body/content/div/form/div/div[12]/div[12]/div[5]/input").send_keys(
            dist["联系地址-号S"])

        self.movedownPage(driver, elementID="next-step1")

        driver.find_element_by_id("textarea1").clear()
        driver.find_element_by_id("textarea1").send_keys(dist["备注"])

        driver.find_element_by_id("next-step1").click()

        # 不动产信息
        self.dbt.changeGotoInfoMessage(driver, dist["不动产类型"], dist["不动产登记类型用例"])

        # 不动产类型信息
        self.dbt.changeGotoWTType(driver, dist["委托类型"], dist["委托类型用例"])

    # 封装一下，支持两种传入，一种是位置，另一种是控件显示
    def movedownPage(self, driver, lineNo=None, elementID=None, elementXPATH=None):
        if driver == "":
            driver = self.driver

        if lineNo is not None:
            js = "var q=document.documentElement.scrollTop=" + str(lineNo)
            driver.execute_script(js)

        if lineNo is None and elementID is not None:
            driver.execute_script("arguments[0].scrollIntoView();", driver.find_element_by_id(elementID))

        if elementXPATH is not None:
            driver.execute_script("arguments[0].scrollIntoView();", driver.find_element_by_xpath(elementXPATH))

        driver.implicitly_wait(5)


if __name__ == "__main__":
    unittest.main()
